/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.web;

import business.Obat;
import business.ObatListing;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author atikahSH
 */
public class ObatEdit extends Servlet {


    public ObatEdit(){
        super();
        setTemplate("/WEB-INF/edit_obat.jsp");
    }

    @Override
    protected void process() {

        setMessage("");
        HttpSession session = getRequest().getSession();
                if (validate_field()) {
                        ObatListing ol = new ObatListing();
                        String uname = (String) session.getAttribute("username");
                        Obat u = ol.getObat(getRequest().getParameter("merk"));
                            u.setMerk(getRequest().getParameter("username"));
                            u.setHarga(getRequest().getParameter("password"));
                            u.setKuantitas(getRequest().getParameter("kuantitas"));
                            u.setDeskripsi(getRequest().getParameter("email"));
                            ol.editObat(u);
                } else {
                try {
                    getResponse().sendRedirect("dataKosong");
                } catch (IOException ex) {
                    Logger.getLogger(ProfileEditServlet.class.getName()).log(Level.SEVERE, null, ex);
                     }
                    }
    }


    boolean check() {
     HttpSession session = getRequest().getSession();
        if (session.getAttribute("username") == null) {
            //members uname = (members) session.getAttribute("username");
            return false;
        }
        return true;
    }

    boolean validate_field() {

        String merk = getRequest().getParameter("merk");
        String deskripsi = getRequest().getParameter("deskripsi");
        String harga = getRequest().getParameter("nama_depan");
        String kuantitas = getRequest().getParameter("nama_belakang");
        if(merk == null||deskripsi == null||harga == null||kuantitas == null){
            return false;
        }

        return true;
    }

}